package com.faxsun.profile.core.service;

import java.util.List;

import javax.annotation.Resource;

import org.broadleafcommerce.common.util.TransactionUtils;
import org.broadleafcommerce.profile.core.domain.Customer;
import org.broadleafcommerce.profile.core.service.CustomerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.faxsun.profile.core.dao.FSAssistantDao;
import com.faxsun.profile.core.domain.FSAssistant;

@Service("blAssistantService")
public class FSAssistantServiceImpl implements FSAssistantService {
	@Resource(name="blAssistantDao")
	protected FSAssistantDao assistantDao;
	
	@Resource(name = "blCustomerService")
	CustomerService customerService;

	@Override
	@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
	public FSAssistant create(String md5) {
		return assistantDao.create(md5);
	}

	@Override
	@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
	public FSAssistant save(FSAssistant assistant) {
		return assistantDao.save(assistant);
	}

	@Override
	public Customer getCustomerByMD5(String md5) {
		List<Customer> customers = assistantDao.readCustomerByMD5(md5);
		return customers == null || customers.isEmpty() ? null : customers.get(0);
	}

}
